﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Xml.Serialization;
namespace CoreModule
{
    /// <summary>
    /// 读卡器列表配置
    /// </summary>
    public class RecognitionDeviceConfigurationInfoCollection:List<DeviceConfigurationInfo>
    {
        static string XmlFilePath = "RecognitionDeviceConfigurationInfoCollection.xml";
         
        public RecognitionDeviceConfigurationInfoCollection Load()
        {
            if (File.Exists(XmlFilePath))
            {
                try
                {
                    using (FileStream fileStream = new FileStream(XmlFilePath, FileMode.OpenOrCreate))
                    {
                       return (RecognitionDeviceConfigurationInfoCollection)new XmlSerializer(typeof(RecognitionDeviceConfigurationInfoCollection)).Deserialize(fileStream);
                    }
                }
                catch (Exception)
                {
                    File.Delete(XmlFilePath);
                }
            }
            return new RecognitionDeviceConfigurationInfoCollection();
        }
        /// <summary>
        /// /
        /// </summary>
        public void Save()
        {
            if (File.Exists(XmlFilePath))
            {
                File.Delete(XmlFilePath);
            }
            try
            {
                using (FileStream fileStream = new FileStream(XmlFilePath, FileMode.OpenOrCreate))
                {
                    new XmlSerializer(typeof(RecognitionDeviceConfigurationInfoCollection)).Serialize(fileStream, this);
                }
            }
            catch (Exception)
            {
            }
        }
    }
}
